package com.ws.game.lesson5.map
{
	import com.ws.game.common.framework.BaseGameObject;
	import com.ws.game.common.framework.BaseGameScene;
	import com.ws.game.common.utils.MapType;
	import com.ws.game.common.utils.PartType;
	import com.ws.game.common.global.Global;
	import com.ws.game.skins.MonsterSkin;
	import com.ws.game.skins.PlayerSkin;
	import com.ws.game.skins.StoneSkin;
	import com.ws.game.skins.BasicSkin;
	import com.ws.game.lesson3.fire.Player;
	import com.ws.game.lesson3.fire.Monster;
	import com.ws.game.lesson3.fire.KeyBoardCtrl;
	import com.ws.game.lesson3.fire.MonsterCtrl;
	import com.ws.game.lesson4.basic.Basic;
	import com.ws.game.lesson4.basic.BasicCtrl;
	
	import flash.display.Stage;
	
	public class MapScen extends BaseGameScene
	{		
		private var _mapData:Array;
		
		public function setup(arr:Array):void
		{
			_mapData = arr;
			if (arr[0] == null || arr[0][0]==null) return;
			
			var y:uint = 0;
			var x:uint;
			
			var obj:BaseGameObject;
			for each(var line:Array in arr)
			{
				x = 0;
				for each(var data:uint in line)
				{
					if (data != 0)
					{
						obj = getObjById(data);
						if (obj != null)
						{
							this.addGameObject(obj);
							obj.x = obj.width * x;
							obj.y = obj.height * y;
						}
					}
					x++;
				}
				y++;
			}
		}
				
		protected function getObjById(id:uint):BaseGameObject
		{
			var result:BaseGameObject=null;
			switch(id)
			{
				case MapType.STONE:
					result = new Stone(new StoneSkin());
					break;
				case MapType.MONSTER:
					result = new Monster(new MonsterCtrl(), new MonsterSkin());
					break;
				case MapType.PLAYER:
					result = new Player(new KeyBoardCtrl(), new PlayerSkin());
					break;
				case MapType.BASE:	
					result = new Basic(new BasicCtrl(),new BasicSkin());
					Global.basic = result;
					break;
			}
			return result;
		}
		
		public function MapScen(_stage:Stage)
		{
			super(_stage);
		}
	}
}